package com.openbravo.pos.admin;

import com.openbravo.basic.BasicException;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.JImageEditor;
import com.openbravo.data.loader.SentenceList;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.data.user.EditorRecord;
import com.openbravo.format.Formats;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.util.Hashcypher;
import com.openbravo.pos.util.StringUtils;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.UUID;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.text.Document;

public class PeopleView extends JPanel
  implements EditorRecord
{
  private Object m_oId;
  private String m_sPassword;
  private DirtyManager m_Dirty;
  private SentenceList m_sentrole;
  private ComboBoxValModel m_RoleModel;
  private JButton jButton1;
  private JButton jButton2;
  private JButton jButton3;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JLabel jLabel5;
  private JTextField jcard;
  private JImageEditor m_jImage;
  private JTextField m_jName;
  private JComboBox m_jRole;
  private JCheckBox m_jVisible;

  public PeopleView(DataLogicAdmin paramDataLogicAdmin, DirtyManager paramDirtyManager)
  {
    initComponents();
    this.m_sentrole = paramDataLogicAdmin.getRolesList();
    this.m_RoleModel = new ComboBoxValModel();
    this.m_Dirty = paramDirtyManager;
    this.m_jName.getDocument().addDocumentListener(paramDirtyManager);
    this.m_jRole.addActionListener(paramDirtyManager);
    this.m_jVisible.addActionListener(paramDirtyManager);
    this.m_jImage.addPropertyChangeListener("image", paramDirtyManager);
    writeValueEOF();
  }

  public void writeValueEOF()
  {
    this.m_oId = null;
    this.m_jName.setText(null);
    this.m_sPassword = null;
    this.m_RoleModel.setSelectedKey(null);
    this.m_jVisible.setSelected(false);
    this.jcard.setText(null);
    this.m_jImage.setImage(null);
    this.m_jName.setEnabled(false);
    this.m_jRole.setEnabled(false);
    this.m_jVisible.setEnabled(false);
    this.jcard.setEnabled(false);
    this.m_jImage.setEnabled(false);
    this.jButton1.setEnabled(false);
    this.jButton2.setEnabled(false);
    this.jButton3.setEnabled(false);
  }

  public void writeValueInsert()
  {
    this.m_oId = null;
    this.m_jName.setText(null);
    this.m_sPassword = null;
    this.m_RoleModel.setSelectedKey(null);
    this.m_jVisible.setSelected(true);
    this.jcard.setText(null);
    this.m_jImage.setImage(null);
    this.m_jName.setEnabled(true);
    this.m_jRole.setEnabled(true);
    this.m_jVisible.setEnabled(true);
    this.jcard.setEnabled(true);
    this.m_jImage.setEnabled(true);
    this.jButton1.setEnabled(true);
    this.jButton2.setEnabled(true);
    this.jButton3.setEnabled(true);
  }

  public void writeValueDelete(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.m_oId = arrayOfObject[0];
    this.m_jName.setText(Formats.STRING.formatValue(arrayOfObject[1]));
    this.m_sPassword = Formats.STRING.formatValue(arrayOfObject[2]);
    this.m_RoleModel.setSelectedKey(arrayOfObject[3]);
    this.m_jVisible.setSelected(((Boolean)arrayOfObject[4]).booleanValue());
    this.jcard.setText(Formats.STRING.formatValue(arrayOfObject[5]));
    this.m_jImage.setImage((BufferedImage)arrayOfObject[6]);
    this.m_jName.setEnabled(false);
    this.m_jRole.setEnabled(false);
    this.m_jVisible.setEnabled(false);
    this.jcard.setEnabled(false);
    this.m_jImage.setEnabled(false);
    this.jButton1.setEnabled(false);
    this.jButton2.setEnabled(false);
    this.jButton3.setEnabled(false);
  }

  public void writeValueEdit(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.m_oId = arrayOfObject[0];
    this.m_jName.setText(Formats.STRING.formatValue(arrayOfObject[1]));
    this.m_sPassword = Formats.STRING.formatValue(arrayOfObject[2]);
    this.m_RoleModel.setSelectedKey(arrayOfObject[3]);
    this.m_jVisible.setSelected(((Boolean)arrayOfObject[4]).booleanValue());
    this.jcard.setText(Formats.STRING.formatValue(arrayOfObject[5]));
    this.m_jImage.setImage((BufferedImage)arrayOfObject[6]);
    this.m_jName.setEnabled(true);
    this.m_jRole.setEnabled(true);
    this.m_jVisible.setEnabled(true);
    this.jcard.setEnabled(true);
    this.m_jImage.setEnabled(true);
    this.jButton1.setEnabled(true);
    this.jButton2.setEnabled(true);
    this.jButton3.setEnabled(true);
  }

  public Object createValue()
    throws BasicException
  {
    Object[] arrayOfObject = new Object[7];
    arrayOfObject[0] = (this.m_oId == null ? UUID.randomUUID().toString() : this.m_oId);
    arrayOfObject[1] = Formats.STRING.parseValue(this.m_jName.getText());
    arrayOfObject[2] = Formats.STRING.parseValue(this.m_sPassword);
    arrayOfObject[3] = this.m_RoleModel.getSelectedKey();
    arrayOfObject[4] = Boolean.valueOf(this.m_jVisible.isSelected());
    arrayOfObject[5] = Formats.STRING.parseValue(this.jcard.getText());
    arrayOfObject[6] = this.m_jImage.getImage();
    return arrayOfObject;
  }

  public Component getComponent()
  {
    return this;
  }

  public void activate()
    throws BasicException
  {
    this.m_RoleModel = new ComboBoxValModel(this.m_sentrole.list());
    this.m_jRole.setModel(this.m_RoleModel);
  }

  public void refresh()
  {
  }

  private void initComponents()
  {
    this.jButton3 = new JButton();
    this.jLabel1 = new JLabel();
    this.m_jName = new JTextField();
    this.m_jVisible = new JCheckBox();
    this.jLabel3 = new JLabel();
    this.jLabel4 = new JLabel();
    this.m_jImage = new JImageEditor();
    this.jButton1 = new JButton();
    this.m_jRole = new JComboBox();
    this.jLabel2 = new JLabel();
    this.jcard = new JTextField();
    this.jButton2 = new JButton();
    this.jLabel5 = new JLabel();
    this.jButton3.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/fileclose.png")));
    this.jButton3.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        PeopleView.this.jButton3ActionPerformed(paramActionEvent);
      }
    });
    this.jLabel1.setText(AppLocal.getIntString("label.peoplename"));
    this.jLabel3.setText(AppLocal.getIntString("label.peoplevisible"));
    this.jLabel4.setText(AppLocal.getIntString("label.peopleimage"));
    this.m_jImage.setMaxDimensions(new Dimension(32, 32));
    this.jButton1.setText(AppLocal.getIntString("button.peoplepassword"));
    this.jButton1.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        PeopleView.this.jButton1ActionPerformed(paramActionEvent);
      }
    });
    this.jLabel2.setText(AppLocal.getIntString("label.role"));
    this.jcard.setEditable(false);
    this.jButton2.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/color_line16.png")));
    this.jButton2.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        PeopleView.this.jButton2ActionPerformed(paramActionEvent);
      }
    });
    this.jLabel5.setText(AppLocal.getIntString("label.card"));
    GroupLayout localGroupLayout = new GroupLayout(this);
    setLayout(localGroupLayout);
    localGroupLayout.setHorizontalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addContainerGap().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel1, -2, 90, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.m_jName, -2, 180, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jButton1)).addGroup(localGroupLayout.createSequentialGroup().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel5, -2, 90, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jcard, -2, 180, -2)).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel2, -2, 90, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.m_jRole, -2, 180, -2))).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jButton2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jButton3)).addGroup(localGroupLayout.createSequentialGroup().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jLabel3, -2, 90, -2).addComponent(this.jLabel4, -2, 90, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.m_jImage, -2, 250, -2).addComponent(this.m_jVisible)))).addContainerGap(129, 32767)));
    localGroupLayout.setVerticalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, localGroupLayout.createSequentialGroup().addContainerGap().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel1).addComponent(this.m_jName, -2, -1, -2).addComponent(this.jButton1)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jButton3).addGroup(localGroupLayout.createSequentialGroup().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel5).addComponent(this.jcard, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel2).addComponent(this.m_jRole, -2, 20, -2))).addComponent(this.jButton2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jLabel3).addComponent(this.m_jVisible)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.m_jImage, -2, 180, -2).addComponent(this.jLabel4)).addGap(246, 246, 246)));
  }

  private void jButton1ActionPerformed(ActionEvent paramActionEvent)
  {
    String str = Hashcypher.changePassword(this);
    if (str != null)
    {
      this.m_sPassword = str;
      this.m_Dirty.setDirty(true);
    }
  }

  private void jButton2ActionPerformed(ActionEvent paramActionEvent)
  {
    if (JOptionPane.showConfirmDialog(this, AppLocal.getIntString("message.cardnew"), AppLocal.getIntString("title.editor"), 0, 3) == 0)
    {
      this.jcard.setText("c" + StringUtils.getCardNumber());
      this.m_Dirty.setDirty(true);
    }
  }

  private void jButton3ActionPerformed(ActionEvent paramActionEvent)
  {
    if (JOptionPane.showConfirmDialog(this, AppLocal.getIntString("message.cardremove"), AppLocal.getIntString("title.editor"), 0, 3) == 0)
    {
      this.jcard.setText(null);
      this.m_Dirty.setDirty(true);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.admin.PeopleView
 * JD-Core Version:    0.6.0
 */